#!/usr/bin python3
# -*- coding:UTF-8 -*-
# Author: nigo
import plotly.express as px
import plotly.graph_objects as go

# 数据
df = px.data.iris()
# 创建每个species对应的颜色
color = {'setosa': 'rgb(147,112,219)',
         'versicolor': 'rgb(220,20,60)',
         'virginica': 'rgb(0,128,0)'}
# 创建一个空画布
fig = go.Figure()
# 画每个species的图（点）
for speciecy in df['species'].unique():
    dfs = df[df['species'] == speciecy]
    scatter = go.Scatter(x=dfs['sepal_width'],y=dfs['sepal_length'],mode='markers',
                        marker_color=color[speciecy],marker_size=dfs['petal_length']*5,
                        name=speciecy)
    fig.add_traces(scatter)
# 更新样式
fig.update_layout(title='鸢尾花散点图',xaxis_title='花萼宽度',yaxis_title='花萼长度',
                 legend_title = 'species') # 设置图例名称为species
# 显示画布
fig.show()

